<template>
    <div class="app-container" v-loading="loading" element-loading-text="加载中...">
        <div class="app-container-inner">
            <el-form ref="ruleFormRef" :model="ruleForm" label-width="auto" class="demo-ruleForm">

                <el-form-item label="厂商审核策略" prop="factoryCheckStrategy">
                    <el-radio-group @change="onsaveFactorySet" v-model="ruleForm.factoryCheckStrategy">
                        <el-radio :value="1">直接通过</el-radio>
                        <el-radio :value="2">需要审核</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="报单余额策略" prop="orderBalanceStrategy">
                    <el-radio-group @change="onsaveFactorySet" v-model="ruleForm.orderBalanceStrategy">
                        <el-radio :value="1">不限制</el-radio>
                        <el-radio :value="2">余额不足禁止下单</el-radio>
                    </el-radio-group>
                </el-form-item>

            </el-form>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getFactorySet, saveFactorySet } from '../../../api/merchant'
import { ElMessage, ElMessageBox } from 'element-plus'
const loading = ref(false)
const ruleForm = ref({
    "factoryCheckStrategy": 1,//	厂商审核策略：1-直接通过，2-需要审核,示例值(1)	
    "orderBalanceStrategy": 1//报单余额策略：1-不限制/余额不足亦可下单，2-余额不足禁止下单,示例值(1)
})
const getFactoryDetailData = async () => {
    loading.value = true
    await getFactorySet().then(res => {
        if (res) {
            ruleForm.value = res.data.data.row
            if (!res.data.success) {
                ElMessage({
                    showClose: true,
                    message: res.data.message,
                    type: 'error',
                })
            }
        }
    })
    loading.value = false
}
const onsaveFactorySet = async () => {
    loading.value = true
    await saveFactorySet(ruleForm.value).then(res => {
        if (res) {
            if (!res.data.success) {
                ElMessage({
                    showClose: true,
                    message: res.data.message,
                    type: 'error',
                })
            } else {
                getFactoryDetailData()
            }
        }
    })
    loading.value = false
}
onMounted(() => {
    getFactoryDetailData()
})
</script>

<style scoped lang="scss">
.app-container {
    height: 100%;

    .app-container-inner {
        display: flex;
        flex-direction: column;
        flex: 1;
    }
}
</style>